package network.chat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

/**
 * @author mubei
 * @date 2021/12/5
 * @description
 */
public class UDPReceive02 {

    public static void main(String[] args) throws Exception  {
        DatagramSocket socket = new DatagramSocket(6666);
        byte bytes[] = new byte[1024];

        while(true){
            DatagramPacket packet =new DatagramPacket(bytes,0,bytes.length);
            socket.receive(packet);
            String s = new String(packet.getData(), 0, packet.getLength());

            if(s.equals("bye")){
                break;
            }
            System.out.println(s);
        }

        socket.close();
    }
}
